package com.woniu.woniu_bx.mapper;

import com.woniu.woniu_bx.pojo.Img;
import com.woniu.woniu_bx.pojo.Moment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName MomentImg
 * @Description TODO
 * @Author 魏才林
 * @Date 2022/9/1 14:22
 * @Version 1.0
 **/
@Repository
public interface MomentImgMapper {

    /**
     * @Description 批量增加动态图片
     **/
    @Insert({"<script>" +
            "insert into bx_moment_img(moment_id,url) values" +
            "<foreach collection='momentImgs' item='img' separator=','>" +
            "(#{momentId},#{img})" +
            "</foreach>" +
            "</script>"})
    void insert(@Param("momentImgs") List<String> momentImgs, Integer momentId);

    /**
     * @Description 批量删除动态图片
     **/
    @Delete({"<script>" +
            "delete from bx_moment_img where id in" +
            "<foreach collection='ids' item='id'  open='('  separator=','  close=')'>" +
            "#{id}" +
            "</foreach>" +
            "and moment_id =#{momentId}" +
            "</script>"})
    void delete(@Param("ids") List<Integer> ids, @Param("momentId") Integer momentId);

    /**
     * @Description 根据动态id查询其所有的图片
     **/
    @Select("select url from bx_moment_img where moment_id=#{momentId}")
    List<String> getAllImgByMomentId(Integer momentId);
}
